#include "lettershell/shell.h"

#include "../shell_log.h"
#include "hal_adapter.h"

#include "misc/misc_api.h"
#include "misc/misc_system.h"

// @TODO:！！！增加指令server用于显示服务器的各个状态
// 1. 服务IP和端口
// 2. 显示服务器状态
// 3. 心跳发送状态
// 4. 激活状态
#include "service/include/swei_active.h"
#include "service/include/swei_login.h"
void shell_server_status_print(void)
{
    uint32_t remain_ms = get_heartbeat_report_next_send();
    uint32_t total_ms = get_heartbeat_total_timecnt();

    printf("**************************************************\r\n");
    printf("network          : %s\r\n", net_ready_check() ? "OK" : "FAIL");
    printf("socket           : %s\r\n", socket_ready_check() ? "OK" : "FAIL");
    printf("login            : %s\r\n", swei_login_is_ok() ? "OK" : "FAIL");
    printf("heartbeat        : %s\r\n", swei_heartbeat_is_ok() ? "OK" : "FAIL");
    printf("countdown        : %ds / %ds\r\n", remain_ms / 1000, total_ms / 1000);
    printf("active status    : %s\r\n", ACTIVE == misc_get_active_state() ? "ACTIVE" : "INACTIVE");
    printf("active req finish: %s\r\n", swei_srv_active_req_finish() ? "OK" : "FAIL");
    printf("login step       : %s\r\n", swei_login_step_get_str());
    printf("**************************************************\r\n");
}
 
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC) | SHELL_CMD_DISABLE_RETURN,
                 server, 
                 shell_server_status_print, 
                 show the server connect status);